package com.culturalCenter.dataCenter.service.impl.volunteer;

import com.culturalCenter.dataCenter.customEntity.responseParam.volunteer.VolunteerSignInResponse;
import com.culturalCenter.dataCenter.entity.volunteer.CdcVolunteerSignuprecord;
import com.culturalCenter.dataCenter.mapper.volunteer.CdcVolunteerSignuprecordMapper;
import com.culturalCenter.dataCenter.service.volunteer.CdcVolunteerSignuprecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 志愿者报名记录(CdcVolunteerSignuprecord)表服务实现类
 *
 * @author makejava
 * @since 2021-09-17 16:10:01
 */
@Service("cdcVolunteerSignuprecordService")
public class CdcVolunteerSignuprecordServiceImpl implements CdcVolunteerSignuprecordService {

    @Resource
    private CdcVolunteerSignuprecordMapper cdcVolunteerSignuprecordMapper;

    @Override
    public CdcVolunteerSignuprecord queryById(String id) {
        return this.cdcVolunteerSignuprecordMapper.queryById(id);
    }

    @Override
    public List<CdcVolunteerSignuprecord> queryAllByLimit(int offset, int limit) {
        return this.cdcVolunteerSignuprecordMapper.queryAllByLimit(offset, limit);
    }

    @Override
    public CdcVolunteerSignuprecord insert(CdcVolunteerSignuprecord cdcVolunteerSignuprecord) {
        this.cdcVolunteerSignuprecordMapper.insert(cdcVolunteerSignuprecord);
        return cdcVolunteerSignuprecord;
    }

    @Override
    public CdcVolunteerSignuprecord update(CdcVolunteerSignuprecord cdcVolunteerSignuprecord) {
        this.cdcVolunteerSignuprecordMapper.update(cdcVolunteerSignuprecord);
        return this.queryById(cdcVolunteerSignuprecord.getId());
    }

    @Override
    public boolean deleteById(String id) {
        return this.cdcVolunteerSignuprecordMapper.deleteById(id) > 0;
    }

    @Override
    public VolunteerSignInResponse signInStatistics() {
        VolunteerSignInResponse signInResponse = new VolunteerSignInResponse();
        Map<String, Integer> sources = new HashMap<>();
        for (int i = 0; i < 8; i++) {
            sources.put(String.valueOf(i), cdcVolunteerSignuprecordMapper.countSources(i) != null ? cdcVolunteerSignuprecordMapper.countSources(i) : 0);
        }
        signInResponse.setSources(sources);
        signInResponse.setStatus(cdcVolunteerSignuprecordMapper.getStatus());
        return signInResponse;
    }

}
